using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace FORUs
{
    public partial class Frm01_TracksWindow : Form
    {
        public Frm01_TracksWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DirectoryInfo directory = new DirectoryInfo(@"C:\Program Files\UltraStar Deluxe\Songs");
            FileInfo[] files = directory.GetFiles("*.txt", SearchOption.AllDirectories);
            UltrastarSong uSong;
            foreach (FileInfo f in files)
            {
                uSong = UltrastarSong.FromFile(f.FullName);
                if (! uSong.IsEmpty)
                    treeView1.Nodes.Add(uSong.Filename, String.Concat(uSong.Artist, " - ", uSong.Title));
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            string filename = treeView1.SelectedNode.Name;
            UltrastarSong usSong = UltrastarSong.FromFile(filename);
            if (usSong.IsEmpty)
                return;

            _txtArtist.Text = usSong.Artist;
            _txtBackground.Text = usSong.BackgroundFilename;
            _txtCover.Text = usSong.CoverFilename;
            _txtEdition.Text = usSong.Edition;
            _txtFilename.Text = usSong.Filename;
            _txtGenre.Text = usSong.Genre;
            _txtLanguage.Text = usSong.Language;
            _txtMP3.Text = usSong.Mp3Filename;
            _txtTitle.Text = usSong.Title;
        }
    }
}